/**
 * 
 */
package com.antilia.infomaresme.provider;

import java.util.Iterator;

import org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider;
import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
import org.apache.wicket.model.IModel;

import com.antilia.infomaresme.InfomaresmeApplication;
import com.antilia.infomaresme.data.dao.interfaces.ICategoryAlertsDao;
import com.antilia.infomaresme.data.dataobjects.CategoryAlert;
import com.antilia.infomaresme.data.dataobjects.User;

/**
 * @author Ernesto
 *
 */
public abstract class CategoryAlertsDataProvider extends SortableDataProvider<CategoryAlert>  implements ISortableDataProvider<CategoryAlert> {

	private static final long serialVersionUID = 1L;
		
	/**
	 * 
	 */
	public CategoryAlertsDataProvider() {
		
	}

	/* (non-Javadoc)
	 * @see org.apache.wicket.model.IDetachable#detach()
	 */
	public void detach() {

	}

	/* (non-Javadoc)
	 * @see org.apache.wicket.markup.repeater.data.IDataProvider#iterator(int, int)
	 */
	public Iterator<? extends CategoryAlert> iterator(int first, int count) {
		//boolean isAscending = (getSort() != null && getSort().getProperty()==null) || (getSort() != null && getSort().isAscending());
		return getAlertsDao().getItems(getUser(), first, count).iterator();
	}

	/* (non-Javadoc)
	 * @see org.apache.wicket.markup.repeater.data.IDataProvider#size()
	 */
	public int size() {
		return getAlertsDao().countItems(getUser()).intValue();
	}

	/* (non-Javadoc)
	 * @see org.apache.wicket.markup.repeater.data.IDataProvider#model(java.lang.Object)
	 */
	public IModel<CategoryAlert> model(CategoryAlert object) {
		return new CategoryAlertsLdm(object);
	}

	protected final ICategoryAlertsDao getAlertsDao() {
		return InfomaresmeApplication.getQAApplication().getCategoryAlertsDao();
	}
	
	public abstract User getUser();
}
